package com.xxxx.server.controller;


import com.xxxx.server.pojo.Position;
import com.xxxx.server.rest.RespBean;
import com.xxxx.server.service.IPositionService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.List;

/**
 * <p>
 *  职位管理
 * </p>
 *
 * @author zhoubin
 * @since 2020-10-15
 */
@RestController
@RequestMapping("/system/basic/pos")
public class PositionController {


    @Resource
    private IPositionService iPositionService;

//    查询所有操作
    @ApiOperation(value = "查询所有职位管理")
    @GetMapping("/select")
    public List<Position>  getAllPositions() {

        return  iPositionService.list();
    }
    //添加操作
    @ApiOperation(value = "添加职位管理")
    @PostMapping("/add")
    public RespBean addPositions(@RequestBody Position position) {
        position.setCreateDate(LocalDateTime.now());
        if (iPositionService.save(position)) {
            return RespBean.success("success");
        } else {
            return RespBean.error("fail");
        }
    }


    //修改操作
    @ApiOperation(value = "修改职位管理")
    @PutMapping("/update")
    public RespBean updatePositions(@RequestBody Position position) {
//        iPositionService.updatePositions(position);
        if (iPositionService.updateById(position)) {
            return RespBean.success("success");
        } else {
            return RespBean.error("fail");
        }
    }



    ////    删除操作
    @ApiOperation(value ="删除职位管理")
    @DeleteMapping("/{id}")
    public RespBean deletePositions(@PathVariable Integer id) {

        if (iPositionService.removeById(id)) {
            return RespBean.success("success");
        } else {
            return RespBean.error("fail");
        }
    }



    //    //批量删除操作
    @ApiOperation(value ="批量删除职位管理")
    @DeleteMapping("/deleteAll")
    public RespBean deleteAllPositions(Integer[] ids) {
        if (iPositionService.removeByIds(Arrays.asList(ids))) {
            return RespBean.success("success");
        } else {
            return RespBean.error("fail");
        }
    }

}
